﻿/*
 * Summary:
 *   The SportsItem class contains details of an individual 
 *   sports item
 *   
 * History:
 *   Date           Author      Changes
 *   23/10/2010     YIWEI YU    Created
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AcmeSportsStore
{
    class SportsItem : IComparable
    {
        protected string mId;
        protected string mName;
        protected string mDescription;
        protected int mPrice;

        public string Id
        { 
            get { return mId; } 
        }
        
        public string Name
        { 
            get { return mName; } 
        }
        
        public string Description
        { 
            get { return mDescription; } 
        }

        public int Price    /* in cent */
        { 
            get { return mPrice; } 
        }

        public string PriceString
        {
            get
            {
                int integerPart = mPrice / 100;
                int fractionalPart = mPrice % 100;
                return integerPart.ToString() + "." + fractionalPart.ToString();
            }
        }

        public SportsItem(string id, string name, string desc, int price)
        {
            mId = id;
            mName = name;
            mDescription = desc;
            mPrice = price;
        }

        /*
         * <summary>
         *  This method is required to implement IComparable
         *  it specifies an ordering relation between SportsItem
         *  objects in terms of ID. IDs should be unique
         * </summary>
         */
        public int CompareTo(object obj)
        {
            SportsItem that = (SportsItem)obj;
            return this.Id.CompareTo(that.Id);
        }

        public override string ToString()
        {
            return mId + "; " + mName + "; " + mDescription + "; " + PriceString;
        }
    }
}
